package com.itheima.homework;

import java.util.Scanner;

public class HomeWork02 {
    public static void main(String[] args) {
        while (true) {
            //目标:掌握字符串的遍历
            //提示输入提示输入身份证号码
            System.out.println("===========身份证校验功能===========");
            System.out.println("请输入您的身份证号码");
            //创建扫描器
            Scanner sc = new Scanner(System.in);
            String idNumber = sc.next();
            System.out.println("结果: " + checkIdNumber(idNumber));
        }
    }

    private static boolean checkIdNumber(String idNumber) {
        //判断长度,必须为18
        if (idNumber.length() != 18) {
            return false;
        }

        //判断是否注意是不为零的数0开头
        /*if (idNumber.startsWith("0") || idNumber.charAt(0) < '1' ||  idNumber.charAt(0) > '9') {
            return false;
        }*/
        if (idNumber.startsWith("0") ) {
            return false;
        }
        //遍历字符串,获取要判断的每一个字符,利用char在底层的特性
        for (int i = 0; i < idNumber.length() - 1; i++) {
            char c = idNumber.charAt(i);
            if (c < '0' || c > '9') {
                return false;
            }
        }
        //对最后一位数据进行判断
        char c = idNumber.charAt(idNumber.length() - 1);
        if (c == 'X' || c >= '0' && c <= '9') {
            return true;
        } else {
            return false;
        }


    }


}
